package com.ojoin.trade.t0loan_core.utils;

import java.util.Date;

import com.ojoin.trade.common.web.domain.IDentifiable;

/**
 * 审计信息工具类
 * @author guoting
 */
public class AuditInfoUtil {

	/**
	 * 单个对象，新增时为对象添加创建时间
	 * @param data
	 */
	public static void createData(Object data) {
		if (data == null) {
			return;
		}
		if (data instanceof IDentifiable) {
			IDentifiable vo = (IDentifiable) data;
			vo.setRowCreateTime(AuditInfoUtil.getCurrentTime());
		}
	}

	/**
	 * 多个对象，新增时为对象添加创建时间
	 * @param datas
	 */
	public static void createData(Object... datas) {
		if (datas == null || datas.length == 0) {
			return;
		}
		Date currentTime = AuditInfoUtil.getCurrentTime();
		for (int i = 0; i < datas.length; i++) {
			if (datas[i] instanceof IDentifiable) {
				IDentifiable vo = (IDentifiable) datas[i];
				vo.setRowCreateTime(currentTime);
			}
		}
	}

	/**
	 * 单个对象，更新时为对象设置更新时间
	 * @param data
	 */
	public static void updateData(Object data) {
		if (data == null) {
			return;
		}
		if (data instanceof IDentifiable) {
			IDentifiable vo = (IDentifiable) data;
			vo.setRowUpdateTime(AuditInfoUtil.getCurrentTime());
		}
	}

	/**
	 * 多个对象，更新时为对象设置更新时间
	 * @param datas
	 */
	public static void updateData(Object... datas) {
		if (datas == null || datas.length == 0) {
			return;
		}
		Date currentTime = AuditInfoUtil.getCurrentTime();
		for (int i = 0; i < datas.length; i++) {
			if (datas[i] instanceof IDentifiable) {
				IDentifiable vo = (IDentifiable) datas[i];
				vo.setRowUpdateTime(currentTime);
			}
		}
	}


	@SuppressWarnings("static-access")
	public static Date getCurrentTime() {
		return new Date();
	}

}
